<?php
include_once('/var/www/html/new/com.inc.php');
include_once '/var/www/html/new/d/module/common/Db.class.php';
$dbConf = include '/var/www/html/new/d/module/common/db.conf.php';// 远端服务器配置信息


if(!isset($_REQUEST['method'])) exit('{"status":"fail","msg":"非法访问","code":101}');



use \PFT\Db;
Db::Conf($dbConf['remote_1']);



switch(trim($_REQUEST['method'])){
	// 获取场馆信息
	case 'GetVenueINF':
		$type     = $_REQUEST['type'] + 0;// 1 获取场馆信息及座位总数  2 获取座位详细
		$venue_id = $_REQUEST['venue_id'] + 0;
		$zone_id  = $_REQUEST['zone_id'] + 0;// 
		$sql = "select * from pft_venues where id=$venue_id limit 1";
		if($venue_id==0 || !($dbResult = Db::fetch($sql))) exit('{"status":"fail","msg":"场馆不存在","code":201}');
		$response = array('venue_name'=>$dbResult['venue_name'],'thumb'=>$dbResult['venue_thumb'], 'status'=>'success', 'code'=>200);
		
		// 获取分区名称
		$response['zone_list'] = array();
		$sql = "select id,zone_name from pft_roundzone where venue_id=$venue_id";
		$dbResult = Db::fetchAll($sql);
		if(count($dbResult)){
			foreach($dbResult as $row) $response['zone_list'][$row['id']] = $row['zone_name'];
		}
		
		$sql = "select * from pft_roundseat where venue_id=$venue_id and seat_status=0";
		if($zone_id>0) $sql.= " and zone_id=$zone_id";
		// echo $sql;
		$dbResult = Db::fetchAll($sql);
		$response['seat_count'] = count($dbResult);
		exit(json_encode($response));
		break;
    case 'GetZone':
        $venue_id = $_REQUEST['venue_id'] + 0;
        $zone_id  = $_REQUEST['zone_id'] + 0;//
        $sql = "select id from pft_venues where id=$venue_id limit 1";
        if($venue_id==0 || !($dbResult = Db::fetch($sql))) exit('{"status":"fail","msg":"场馆不存在","code":201}');
        $response = array('venue_name'=>$dbResult['venue_name'],'thumb'=>$dbResult['venue_thumb'], 'status'=>'success', 'code'=>200);
        // 获取分区名称
        $sql = "select id,zone_name from pft_roundzone where venue_id=$venue_id AND id=$zone_id LIMIT 1";
        $response['zone_list'] = Db::fetchAll($sql);
        $sql = "select count(id) as cnt from pft_roundseat where venue_id=$venue_id AND zone_id=$zone_id AND seat_status=0";
//        if($zone_id>0) $sql.= " and zone_id=$zone_id";
        // echo $sql;
        $dbResult = Db::fetch($sql);
        $response['seat_count'] = $dbResult['cnt'];
        echo json_encode($response);
        break;
	default:exit('{"status":"fail","msg":"无权限访问","code":101}');break;
}
Db::Close();
